package 剑指offer;

/**
 * @Description:
 * @Author: Administrator
 * @Date: 2020-05-05
 */
public class 删除链表中重复的结点 {


    public static ListNode deleteDuplication(ListNode pHead) {


        ListNode head = new ListNode(0);
        head.next = pHead;
        ListNode temp = head.next;
        ListNode preNode = head;
        while (temp != null) {
            if (temp.next!=null&&temp.val == temp.next.val) {
                while (temp.next != null && temp.val == temp.next.val) {
                    temp = temp.next;
                }
                preNode.next = temp.next;
                temp = temp.next;

            }else{
                preNode = temp;
                temp = temp.next;
            }
        }
        return head.next;
    }

    public static void main(String[] args) {
//        1->2->3->3->4->4->5   =   1->2->5
        int[] arr = { 1, 1, 1, 1, 1, 1, 1};
//        int[] arr = {1, 2, 2,3,3, 4,4, 5,5};
        deleteDuplication(ListNode.buildNode(arr));
    }
}
